<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/uploadify/jquery.uploadify.min.js" ></script>
<link rel="stylesheet" charset="utf-8" type="text/css" href="__PUBLIC__/admin/js/uploadify/uploadify.css"> 
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/upload.js" ></script>
<style type="text/css">
#feng{ width: 100%; overflow: hidden; float: left; margin: 5px; }
.bg{ background: none; border: none;}
label{ font-size: 16px;}
.uploadify-button-text{ display: inline-flex; }
.uploadify-button-text button{ margin: -10px; }
.upviewer img{ height:90px; width: 120px; }
.upviewer ul{ margin:0px; padding:0px; }
.upviewer li{ margin:0px; padding:0px; position: relative; display:inline-block; width:120px; height:90px; background-position: center; background-size: contain; background-repeat: no-repeat; float: left; margin-right:10px; border:1px #ccc solid; background-color:#f0f0f0;}
.upviewer li a{ display:inline-block; position: absolute; bottom:0px; left:0px; text-align:center; width:100%; background-color:rgba(0,0,0,0.3); color:red; cursor: pointer; }
.upviewer li:hover a{ background-color:rgba(0,0,0,0.8); }
</style>
 <div class="container-fluid">
  <div class="row-fluid">
    <div class="span12">
    <form role="form" id="form" action="{:U('Activity/update_research',array('id'=>$list['id']))}" onsubmit="return validation()">    
    <div class="form-group">
      <label for="name">问卷调查的标题</label>
      <input type="text" class="form-control" value="{$list.name}" name="title" required="required" />
   </div>
    <!-- 内容描述 -->
   <div class="form-group">
      <label for="name">描述</label>
      <input type="text" class="form-control" value="{$list.description}" name="description" required="required" />
   </div>
  
     <!-- <div class="form-group">
      <label for="name">选择奖品</label>
      <select name="aid" form="form">
        <option value="{$arr.id}">
            <if condition="$list.aid eq '0'">无奖品</if>
            <if condition="$list.aid neq '0'">{$arr.name}</if>
        </option>    
        <option value="{$v.id}">
          {$v.name}
        </option>
      </select>
        </div> -->

     <div class="form-group">
      <label for="name">允许参加的客户</label>
      <select name="access" >
      	<option value="0" <if condition="$list['access'] eq 0">selected="selected"</if>>全部</option>
      <!--	<option value="1" <if condition="$list['access'] eq 1">selected="selected"</if>>普通客户</option>-->
      	<option value="2" <if condition="$list['access'] eq 2">selected="selected"</if>>优质客户</option>
      </select>
   </div>
   
      <div class="checkbox">
      <label>
         <volist name="v" id="data">
             <br />
             <input type="checkbox" name="checkbox[]" value="{$data.id}"  
            <foreach name="arr" item="v">
            <if  condition="$data.id eq $v">
              checked
            </if>
            </foreach>     
            />
          {$data.name}
         </volist> 
      </label>
   </div>

   <div id="feng">
   <div class="form-group">
    
      <label for="upload"><span style="color: red;">*</span>封面照片<span style="color: red;">(只能有1张)</span></label>
      <input type="file" class="form-control" id="upload" placeholder="图片上传"> <br />
      <input type="hidden" name="cover" id="img">
      <div id="view" class="upviewer" style="height:200px;"> {$list.img}</div>
        
     </div>
  </div>

     <!-- 问卷调查的状态 -->
 <div class="form-group">
     <label for="name">是否开启</label>
      <div class="radio">
        <label>
          <input type="radio" name="state"  value="0" <if condition="$list['state'] eq '0'"> checked </if> />
         关闭
        </label>
      </div>
      <div class="radio">
        <label>
          <input type="radio" name="state"  value="1" <if condition="$list['state'] eq '1'"> checked </if> />
         开启
        </label>
    </div>
</div>
    <button type="submit" class="btn btn-default">提交</button>
</form>
    </div>
  </div>
</div>

<script type="text/javascript">

$(function(){
  initDelFile();

  initUploadify({ ID:'upload',url:"{:U('Upload/upload')}",success:function(obj){ 
    if(obj.s){
      $('#view').append('<li><img src="'+obj.d+'"/><a d_path="'+obj.d+'">删除</a></li>');
      initDelFile();
    }else{
      alert(obj.m);
    }
  } });
});

function initDelFile(){
  $('.upviewer li a').unbind('click').click(function(){
    if(!confirm('你确认删除吗?')) return false;
    var _this = $(this);
    var dpath = $(_this).attr('d_path');
    if(!dpath) return false;
    $.post('{:U('Upload/delfile')}',{filepath:dpath},function(obj){ 
      if(obj.s){ 
        $(_this).parents('li').remove();
      }else{
        alert(obj.m);
        $(_this).parents('li').remove();
      } 
    },'json');
  });
}
  function validation(){  
  var img=$('#view').html().trim();//获取值    
    var listimg=$('#img').val(img);//写入值
    var listnum=document.getElementById("view").getElementsByTagName("img");//验证数量
    if(img=="")
    {
      alert('请上传一张图');
       return false; 
    }
    if(listnum.length>1)
    {
      alert('列表图只能有一张');
       return false; 
    }

}



</script>